// 导入组件
import Vue from 'vue';
import Router from 'vue-router';

import PageRouter from './page/'
import Store from '../store/'
import autorouter from './autorouter'
// 启用路由
Vue.use(Router);

// 导出路由
let router =  new Router({
  scrollBehavior (to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      if (from.meta.keepAlive) {
        from.meta.savedPosition = document.body.scrollTop
      }
      return {
        x: 0,
        y: to.meta.savedPosition || 0
      }
    }
  },
  routes: [].concat([])

})

// const originalPush = Router.prototype.push
// Router.prototype.push = function push(location) {
//   return originalPush.call(this, location).catch(err => err)
// }


autorouter.install(router, Store)
console.log('\n')
console.log('%c!<-------------------- 动态(菜单)路由 start -------------------->', 'color:blue')
router.$routers.formatRoutes(Store.state.user.menu, true)
console.log(Store.state.user.menu)
console.log('%c!<-------------------- 动态(菜单)路由 end -------------------->', 'color:blue')
router.addRoutes(PageRouter)
export  default router;
